<?php
namespace Application\Component;
use Doctrine\ORM\EntityManager;
use Application\Entity\UserFacebook;
use DateTime;
use Application\Component\AbstractComponent;
/**
 * UserServcie
 *
 */
class UserFacebookComponent extends  AbstractComponent
{
    protected  $entity="Application\\Entity\\UserFacebook";

    public function __construct(EntityManager $em)
    {
        $this->em = $em;
    }

	function insert($userFacebook)
	{
		$datetime = new DateTime('now');
		$userFacebook->createdAt = $datetime;
		$userFacebook->modifiedAt = $datetime;
		$this->em->persist($userFacebook);
		$this->em->flush();
	}
	
	
	function update($userFacebook)
	{
		$datetime = new DateTime('now');
		$userFacebook->modifiedAt = $datetime;
		$this->em->persist($userFacebook);
		$this->em->flush();
	}
	
	function get($uid)
	{
		$userFacebook = $this->em->find($this->entity, $uid);
		return  $userFacebook;
	}
	
	function getAll()
	{
		$userFacebook = $this->em->getRepository($this->entity)->findAll();
		return  $userFacebook;
	}
	
	function getByUid($uid)
	{
		$userFacebook = $this->em->getRepository($this->entity)->getByUid($uid);
		return  $userFacebook;
	}
	
	function getUniqueByUid($uid)
	{
		$userFacebook = $this->em->getRepository($this->entity)->getUniqueByUid($uid);
		return  $userFacebook;
	}
	
	function getByUsername($username)
	{
		$userFacebook = $this->em->getRepository($this->entity)->getByUsername($username);
		return  $userFacebook;
	}
	
	function getByEmail($email)
	{
		$userFacebook = $this->em->getRepository($this->entity)->getByEmail($email);
		return  $userFacebook;
	}
	

	
	function delete($id)
	{
		$userFacebook = $this->em->find($this->entity, $id);
		$this->em->remove($userFacebook);
		$this->em->flush();
	}
	
	public function getListUserFacebook($arrayUserFacebookId)
	{
		$mapUserFacebooks = array();
		$userFacebooks = $this->em->getRepository($this->entity)->getListUserFacebook($arrayUserFacebookId);
		foreach ($userFacebooks as $userFacebook)
		{
			$mapUserFacebooks[$userFacebook->uid] = $userFacebook;
		}
		return $mapUserFacebooks;
	}
}
